package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.UmsCommunity;
import com.macro.mall.portal.service.UmsCommunityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 社区表(ums_community）
* @author gaodx
* @create 2020-08-11 15:43
**/
@Slf4j
@RestController
@RequestMapping("umsCommunity")
@Api(tags = "UmsCommunityController", description = "社区表(ums_community）")
public class UmsCommunityController {


    @Autowired
    UmsCommunityService umsCommunityService;



    @ApiOperation("社区列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<UmsCommunity>> list(@ApiParam("请求参数") @RequestBody UmsCommunity request) {
        List<UmsCommunity> umsDept = umsCommunityService.find(request);
        return CommonResult.success(CommonPage.restPage(umsDept));
    }


    @ApiOperation("添加社区")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult save(@RequestBody UmsCommunity request) {
        try {
            umsCommunityService.saveNotNull(request);
            return CommonResult.success(null);
        } catch (Exception e) {
            log.error("", e);
        }
        return CommonResult.failed();

    }

    @ApiOperation("查询社区详情")
    @RequestMapping(value = "/getById", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult getById(@ApiParam(value = "id") @RequestParam(value = "id", required = true) Long id) {
        try {
            UmsCommunity umsDept = umsCommunityService.findOne(id);
            return CommonResult.success(umsDept);
        } catch (Exception e) {
            log.error("", e);
        }
        return CommonResult.failed();
    }


   /* @ApiOperation("删除机构信息")
    @RequestMapping(value = "/delById", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult deleteMenberById(@ApiParam(value = "id") @RequestParam(value = "id", required = true) Long id) {
        try {
            UmsCommunity umsDept = new UmsCommunity();
            umsDept.setId(id);
            umsDept.setStatus(1);
            umsCommunityService.updateNotNullById(umsDept);
            return CommonResult.success(null);
        } catch (Exception e) {
            log.error("", e);
        }
        return CommonResult.failed();

    }

    @ApiOperation("更新机构信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@ApiParam(value = "请求报文") @RequestBody UmsCommunity request) {
        try {
            umsCommunityService.updateNotNullById(request);
            return CommonResult.success(null);
        } catch (Exception e) {
            log.error("", e);
        }
        return CommonResult.failed();

    }
*/


}